import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Top from '@/components/Top'
import Login from '@/components/Login'
import baseServiceOrderSearch from '@/components/baseServiceOrderSearch'
import baseServiceOrderAdd from '@/components/baseServiceOrderAdd'
import baseServiceOrderStatistics from '@/components/baseServiceOrderStatistics'
import baseServiceOrderStatisticsTmp from '@/components/baseServiceOrderStatisticsTmp'


function requireAuth (to, from, next) {
  if (!localStorage.isLogin) {
    next({
      path: '/',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
}

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      components: {
        default: Login,
        // top: Top
      }
    },
    {
      path: '/baseServiceOrderSearch',
      name: 'baseServiceOrderSearch',
      components: {
        default: baseServiceOrderSearch,
        top: Top
      },
      beforeEnter: requireAuth
    },
    {
      path: '/baseServiceOrderAdd',
      name: 'baseServiceOrderAdd',
      components: {
        default: baseServiceOrderAdd,
        top: Top
      },
      beforeEnter: requireAuth
    },
    {
      path: '/baseServiceOrderStatistics',
      name: 'baseServiceOrderStatistics',
      components: {
        default: baseServiceOrderStatistics,
        top: Top
      },
      beforeEnter: requireAuth
    },
    {
      path: '/baseServiceOrderStatisticsTmp',
      name: 'baseServiceOrderStatisticsTmp',
      components: {
        default: baseServiceOrderStatisticsTmp,
        top: Top
      },
      beforeEnter: requireAuth
    },
    {
      path: '*',
      name: 'all',
      components: {
        default: Login,
      },
    }
  ]
})
